package com.yq.day28;

import java.util.concurrent.TimeUnit;

/**
 * 同步代码块的执行流程
 *
 * @author 3307235355@qq.com
 * @since 2022/06/28 16:41
 */
public class Demo04 {
    public static final Object OBJECT=new Object();
    public static void main(String[] args) {
        //创建启动线程
        new Thread(()->{

            synchronized (OBJECT){
                System.out.println("t1访问了sync内容");
                //故意的制造延时
                try {
                    TimeUnit.SECONDS.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t1").start();


        // // main 休眠
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        //创建启动线程
        new Thread(()->{
            System.out.println("t2已经执行了");
            synchronized (OBJECT){
                System.out.println("t2访问的sync的内容");
            }
        },"t2").start();
    }
}
